package cool.taomu.web.controller.mqtt

import cool.taomu.entity.ServerInfo
import cool.taomu.mqtt.mqttv3.MqttCallback
import cool.taomu.mqtt.mqttv3.Topic
import cool.taomu.utils.GuavaCache
import cool.taomu.utils.inter.IStorage
import cool.taomu.web.entity.Message
import org.apache.commons.lang3.SerializationUtils
import org.slf4j.LoggerFactory

@Topic(value=#["taomu/jvm/info"])
class JvmInfoMqttCallback extends MqttCallback {
	val LOG = LoggerFactory.getLogger(JvmInfoMqttCallback);
	IStorage is = GuavaCache.instance;
	val static hm = newHashMap();
	
	override message(String topic, byte[] message) {
		var info = SerializationUtils.deserialize(message) as ServerInfo;
		LOG.info("jvm info mqtt call back:{}",info.toString());
		var msg = new Message();
		msg.type = "jvminfo";
		hm.put(info.host,info);
		msg.data = hm.values;
		is.put("taomu/jvm/info","jvminfo",msg);
		return null;
	}

}
